<%@page import="org.firestorm.traficforecast.database.User"%>
<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!-- session start -->
<!DOCTYPE html>
<html>
<head>
<title>Map Admin</title>
<link rel="Icon" href="images/fav_icon.png" type="image/gif" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- Mobile meta -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Form styleshets -->
<link rel="stylesheet" type="text/css" href="../css/smart-forms.css">
<link rel="stylesheet" type="text/css"
	href="../css/smart-themes/green.css">
<link rel="stylesheet" type="text/css"
	href="../css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="../css/smart-addons.css">
<link rel="stylesheet" type="text/css"
	href="../css/font_awesome/css_awesome/font-awesome.min.css">
<link rel="stylesheet" type="text/css"
	href="../css/font_awesome/css_awesome/font-awesome.css">

<script type="text/javascript" src="../js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="../js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../js/additional-methods.min.js"></script>
<script type="text/javascript" src="../js/jquery.md5.js"></script>

<script type="text/javascript"
	src="../plugins/bootstrap/js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css"
	href="../plugins/bootstrap/css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css"
	href="../plugins/bootstrap/css/bootstrap.css">

<!-- Placeholder support in IE9 and below -->
<!--[if lte IE 9]>
    <script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../js/jquery.placeholder.min.js"></script>
    <![endif]-->
<!-- IE8 Fallback styling -->
<!--[if lte IE 8]>
    <link type="text/css" rel="stylesheet" href="../css/smart-forms-ie8.css">
    <![endif]-->

</head>
<%
	String uploadMessage = request.getParameter("message");
%>
<body>
	<input type="hidden" id="upload-message" value="<%=uploadMessage%>">
	<div class="smart-wrap">

		<!-- chÆ°a cÃ³ session login -->

		<%
			if (session.getAttribute("user") == null) {
		%>
		<div class="smart-forms smart-container wrap-3">
			<form method="post" action="" id="register">
				<div class="form-body">
					<div class="spacer-b30">
						<div class="tagline">
							<span>Đăng nhập quản trị viên</span>
						</div>
					</div>
					<div class="frm-row">
						<div class="section colm colm5">
							<label for="name" class="field-label">Tên đăng nhập</label>
						</div>
						<div class="section colm colm7">
							<label for="username" class="field prepend-icon"> <input
								name="username" id="username" type="text" class="gui-input"
								placeholder="Tên đăng nhập"> <label for="username"
								class="field-icon"><i class="fa fa-user"></i></label>
							</label> <em for="username" id="username_error" class="state-error">Tên
								đăng nhập không được bỏ trống!</em>
						</div>
					</div>
					<div class="frm-row">
						<div class="section colm colm5">
							<label for="name" class="field-label">Mật khẩu</label>
						</div>
						<div class="section colm colm7">
							<label for="password" class="field prepend-icon"> <input
								type="password" name="password" id="password" class="gui-input"
								placeholder="Mật khẩu"> <label for="password"
								class="field-icon"><i class="fa fa-lock"></i></label>
							</label> <em for="password" id="password_error" class="state-error">Mật
								khẩu không được bỏ trống!</em>
						</div>
					</div>
					<em for="login-error" id="login_error" class="state-error">Đăng
						nhập không thành công. Tên đăng nhập hoặc mật khẩu không chính
						xác!</em>
				</div>
				<div class="form-footer" style="text-align: center">
					<button type="button" class="button btn-green" id="btn_login">Đăng
						nhập</button>
				</div>
			</form>
		</div>
		<%
			} else {
				User user = (User) session.getAttribute("user");
		%>

		<!-- cÃ³ session login  -->
		<div class="smart-forms smart-container wrap-1">
			<div class="form-body">
				<div class="spacer-b30">
					<div class="tagline">
						<span>Cấu hình hệ thống</span>
					</div>
				</div>
				<form method="post" id="form-hedge"
					action="../process/upload.jsp?id=hedge" method="post"
					enctype="multipart/form-data">
					<div class="frm-row">
						<div class="section colm colm3">
							<label for="filedaiso" class="field-label">Up Load File
								Đại số gia tử</label>
						</div>
						<div class="section colm colm9">
							<label class="field prepend-icon file"> <span
								class="button btn-primary"> Choose File </span> <input
								type="file" class="gui-file" name="filedaiso" id="file_dai_so"
								onchange="document.getElementById('uploader1').value = this.value;">
								<input type="text" class="gui-input" id="uploader1"
								placeholder="no file selected" readonly=""> <label
								class="field-icon"><i class="fa fa-upload"></i></label>
							</label> <em for="filedaiso" id="filedaiso_error" class="state-error">Vui
								lòng chọn file cần upload!</em>
						</div>
						<em for="filedaiso" id="daiso_error" class="state-error">Cập
							nhật không thành công, vui lòng thử lại!</em>
					</div>
					<div class="form-footer"
						style="text-align: center; background: #ffffff">
						<button type="button" class="button btn-green" id="btn_filedaiso">Cập
							nhật đại số gia tử</button>
					</div>
				</form>
				<form method="post" style="margin-top: 30px;" id="form-map"
					action="../process/upload.jsp?id=map"
					enctype="multipart/form-data">
					<div class="frm-row">
						<div class="section colm colm3">
							<label for="filebando" class="field-label">Up Load File
								Dữ liệu bản đồ</label>
						</div>
						<div class="section colm colm9">
							<label class="field prepend-icon file"> <span
								class="button btn-primary"> Choose File </span> <input
								type="file" class="gui-file" name="filebando" id="file_ban_do"
								onchange="document.getElementById('uploader2').value = this.value;">
								<input type="text" class="gui-input" id="uploader2"
								placeholder="no file selected" readonly=""> <label
								class="field-icon"><i class="fa fa-upload"></i></label>
							</label> <em for="filebando" id="filebando_error" class="state-error">Vui
								lòng chọn file cần upload!</em>
						</div>
						<em for="filebando" id="bando_error" class="state-error">Cập
							nhật không thành công, vui lòng thử lại!</em>
					</div>
					<div class="form-footer"
						style="text-align: center; background: #ffffff">
						<button type="button" class="button btn-green" id="btn_filebando">Cập
							nhật bản đồ</button>
					</div>
				</form>
			</div>
		</div>
		<%
			}
		%>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		var message = $("#upload-message").val();
		if (message == "id_null") {
			alert("Some error in your url!");
		} else if (message == "hedge_Ok") {
			alert("Hedge data upload successfull!");
		} else if (message == "hedge_filenamewrong") {
			alert("Hedge data file type not correct!");
		} else if (message == "hedge_failed") {
			alert("Cannot upload Hedge file!");
		} else if (message == "map_Ok") {
			alert("Map data upload successfull!");
		} else if (message == "map_filenamewrong") {
			alert("Map data file type not correct!");
		} else if (message == "map_failed") {
			alert("Cannot upload Map file!");
		}
	});
</script>
<script type="text/javascript">
	$('#btn_login')
			.click(
					function() {
						var username = $('#username').val();
						var password = $('#password').val();

						if (username == "" || password == "") {
							if (username == "") {
								$('#username_error').show();
							}
							if (password == "") {
								$('#password_error').show();
							}
						} else {
							var objLogin = ({
								user : username,
								pass : password
							});
							var jsonobj = JSON.stringify(objLogin);
							var linksss = "http://"
									+ location.host
									+ "/traficforecast/process/checklogin.jsp?id=login&p=admin";
							$.ajax({
								data : {
									para : jsonobj
								},
								dataType : 'json',
								url : linksss,
								type : 'POST',
								success : function(result) {
									if (result.res) {

										window.location.href = 'index.jsp';
									} else {
										$("#login_error").show();
									}
								},
								error : function() {

									alert('Ajax readyState: ' + xhr.readyState
											+ '\nstatus: ' + xhr.status + ' '
											+ err);
								}
							});
						}
					});
</script>
<script type="text/javascript">
	$('#btn_filedaiso').click(function() {
		var file_dai_so = $('#file_dai_so').val();
		if (file_dai_so == "") {
			$('#filedaiso_error').show();
		} else {
			// 			var linksss = "http://"+ location.host + "/traficforecast/process/upload.jsp";
			// 			$.ajax({
			// 				url: linksss,
			// 				type: "POST",
			// 				contentType: "application/json; charset=utf-8",
			// 				data: file_dai_so,
			// 				success: function(result){
			// 					if(result) {
			// 						alert('ok.');
			// 					} else {
			// 						$('#daiso_error').show();
			// 					}
			// 				},
			// 				error: function (xhr, status, err) {
			// 					$('#daiso_error').show();
			// 				},
			// 			});
			$("#form-hedge").submit();
		}
	});
</script>
<script type="text/javascript">
	$('#btn_filebando').click(function() {
		var file_ban_do = $('#file_ban_do').val();
		if (file_ban_do == "") {
			$('#filebando_error').show();
		} else {
			// 			$.ajax({
			// 				url : "",
			// 				type : "POST",
			// 				contentType : "application/json; charset=utf-8",
			// 				data : file_dai_so,
			// 				success : function(result) {
			// 					if (result) {
			// 						alert('ok.');
			// 					} else {
			// 						$('#bando_error').show();
			// 					}
			// 				},
			// 				error : function(xhr, status, err) {
			// 					$('#bando_error').show();
			// 				},
			// 			});
			$("#form-map").submit();
		}
	});
</script>
</html>